package com.lxr0860.lxr0860production_test.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.lxr0860.lxr0860production_test.R;
import com.lxr0860.lxr0860production_test.bean.FactoryTestItem;

import java.util.List;

/**
 * Created by uniriho on 2018/10/26.
 */

public class StrengthListAdapter extends BaseAdapter {
    private Context mContext;
    private List<FactoryTestItem> items;

    public StrengthListAdapter(Context context, List<FactoryTestItem> items){
        this.mContext=context;
        this.items=items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder=null;
        if(convertView==null){
            convertView= LayoutInflater.from(mContext)
                    .inflate(R.layout.item_strength_layout,parent,false);
            holder=new Holder();
            holder.mIvIcon= (ImageView) convertView.findViewById(R.id.iv_strength_item_icon);
            holder.mTvTitle= (TextView) convertView.findViewById(R.id.tv_strength_item_title);
            convertView.setTag(holder);
        }else {
            holder= (Holder) convertView.getTag();
        }
        holder.mIvIcon.setImageResource(items.get(position).getBut_bg_id());
        holder.mTvTitle.setText(items.get(position).getTitle());
        return convertView;
    }

    class Holder{
        ImageView mIvIcon;
        TextView mTvTitle;
    }
}
